package com.simpleframe.views.ui;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import com.simpleframe.views.components.Component;
import com.simpleframe.views.components.Message;
import com.simpleframe.web.action.SimpleframeAction;


public class MessageTag extends ComponentTagSupport {
	
	private static final long serialVersionUID = 2074596370942301565L;
	
	public Component getModelBean() {
		return new Message();
	}
	
	@Override
	protected void populateParameters() {
		super.populateParameters();
		Message message = (Message)component;
		HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
		message.setErrors((Collection<String>) request.getAttribute("errors"));
		message.setMessages((Collection<String>) request.getSession().getAttribute(SimpleframeAction.MESSAGES_SESSION));
		request.getSession().removeAttribute(SimpleframeAction.MESSAGES_SESSION);
	}
}
